package com.example.mcpclient.repository;


import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.document.Document;

import java.util.List;

/**
 * @author xuguang
 */
public class DocumentMessageConvert {


    public static Message toMessage(Document document) {
        return UserMessage.builder()
                .metadata(document.getMetadata())
                .text(document.getText())
                .build();
    }

    public static List<Document> toDocuments(String conversationId, List<Message> messages) {
        return messages.stream().map(m -> toDocument(m, conversationId)).toList();
    }


    private static Document toDocument(Message message, String conversationId) {
        return Document.builder()
                .metadata(message.getMetadata())
                .metadata("conversationId", conversationId)
                .text(message.getText())
                .build();
    }
}
